<!DOCTYPE html>
<html>
<head>
    <title>攻略系列</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/plugins/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/plugins/jquery/jquery.min.js"></script>
    <script src="/js/plugins/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategyCatalogs.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/css/dialog.css"/>
    <script src="/js/plugins/dialog2/js/dialog.min.js"></script>
    <script src="/js/common.js"></script>

    <script>
        $(function () {
            var user = JSON.parse(sessionStorage.getItem("user"));
            var params = getParams();
            if (params){
                $.get('/strategies/'+params.strategyId,function (data) {
                    $('.title').html(data.title);
                });
                var index = 1;
                $.get('/strategyCatalogs/'+params.strategyId,function (data) {
                    $('.catalogs').renderValues({list:data},{
                        getName:function (item, value) {
                            $(item).html(index++ +"/"+value);
                        },
                        getHref: function (item, value) {
                            var href = $(item).data('href');
                            $(item).attr('href', href + value);
                        }
                    })
                });

                $.get("/strategyComments/"+params.strategyId+"/b",function (data) {
                    $('#comment').renderValues({list:data}, {
                        getHref:function (item,value) {
                            var tempstar="";
                            var tempo="";
                            var value = parseInt(value)
                            for(var i=0;i<value;i++){
                                tempstar+='<i class="fa fa-star"></i>';
                            }
                            for(var i=0;i<5-value;i++){
                                tempo+='<i class="fa fa-star-o"></i>';
                            }
                            $(item).html(tempstar+tempo);
                        },
                        getImgs:function (item, value) {
                            var imgs=value.split(';');
                            var temp='';
                            for(var i=0;i<imgs.length-1;i++){
                                temp+='<li><img src='+imgs[i]+'></li>';
                            }

                            $(item).html(temp);
                        },
                        getId:function (item,value) {
                            var href =  $(item).data('href');
                            $(item).attr('href', href + value);
                        }
                    });
                })
            }
            $.get("/strategies/travels",{strategyId:params.strategyId},function (data) {
                $('.hot').renderValues(data,{
                    getHref: function (item, value) {
                        var href = $(item).data('href');
                        $(item).attr('href', href + value);
                    }
                });
            });
            //进入点评界面
            $('#commentBtn').click(function () {
                window.location.href="/mine/addComment.html?strategyId="+params.strategyId;
            });


            //收藏
            if(user){
                //通过传送用户id和游记id去判断该游记是否已经被收藏,如果被收藏则显示实心的五角星
                $.get('/collectionces/statusId',{userId:user.id, strategyId:params.strategyId},function (data) {
                    console.log(data);
                    if (data) {
                        $('#collectBtn').removeClass('fa fa-heart-o');
                        $('#collectBtn').addClass('fa fa-heart');
                    }
                });
            }

            $('#collectBtn').click(function () {
                if(user){
                    //通过传送用户id和游记id去判断该游记是否已经被收藏,如果被收藏则显示实心的五角星
                    $.get('/collectionces/statusId',{userId:user.id, strategyId:params.strategyId},function (data) {
                        if (data) {
                            $.ajax({
                                type:'put',
                                url:'/collectionces',
                                data:{userId:user.id, strategyId:params.strategyId},
                                success:function (data) {
                                    if (data.success) {
                                        $('#collectBtn').removeClass('fa fa-heart');
                                        $('#collectBtn').addClass('fa fa-heart-o');
                                        var num1 = $('#b').html();
                                        num = parseInt(num1)-1;
                                        $('#b').html(num);
                                    }
                                }
                            })
                        }else{
                            $.ajax({
                                type:'post',
                                url:'/collectionces',
                                data:{userId:user.id, strategyId:params.strategyId},
                                success:function (data) {
                                    if (data.success) {
                                        $('#collectBtn').removeClass('fa fa-heart-o');
                                        $('#collectBtn').addClass('fa fa-heart');
                                        var num2 = $('#b').html();
                                        num = parseInt(num2)+1;
                                        $('#b').html(num);
                                    }
                                }
                            })
                        }
                    });
                }
            })


            //点赞
            if(user){
                //通过传送用户id和游记id去判断该游记是否已经被收藏,如果被收藏则显示实心的五角星
                $.get('/clicks/statusId',{userId:user.id, strategyId:params.strategyId},function (data) {
                    console.log(data);
                    if (data) {
                        $('#likeBtn').removeClass('fa fa-thumbs-o-up');
                        $('#likeBtn').addClass('fa fa-thumbs-up');
                    }
                });
            }

            $('#likeBtn').click(function () {
                if(user){
                    //通过传送用户id和游记id去判断该游记是否已经被收藏,如果被收藏则显示实心的五角星
                    $.get('/clicks/statusId',{userId:user.id, strategyId:params.strategyId},function (data) {
                        if (data) {
                            $.ajax({
                                type:'put',
                                url:'/clicks',
                                data:{userId:user.id, strategyId:params.strategyId},
                                success:function (data) {
                                    if (data.success) {
                                        $('#likeBtn').removeClass('fa fa-thumbs-up');
                                        $('#likeBtn').addClass('fa fa-thumbs-o-up');
                                       var count1 = $('#a').html()
                                        count = parseInt(count1)-1;
                                        $('#a').html(count)
                                    }
                                }
                            })
                        }else{
                            $.ajax({
                                type:'post',
                                url:'/clicks',
                                data:{userId:user.id, strategyId:params.strategyId},
                                success:function (data) {
                                    if (data.success) {
                                        $('#likeBtn').removeClass('fa fa-thumbs-o-up');
                                        $('#likeBtn').addClass('fa fa-thumbs-up');
                                        var count2 = $('#a').html()
                                        count = parseInt(count2)+1;
                                        $('#a').html(count)
                                    }
                                }
                            })
                        }
                    });
                }
            })

            //获取点赞总数
            var count;
            console.log(count);
            $.get('clicks',{strategyId:params.strategyId},function (data) {
                    count = data;
                console.log(count);
                    $('#a').html(count);
            })

            //获取收藏数
            var num;
            $.get('/collectionces/strategyId',{strategyId:params.strategyId},function (data) {
                num = data;
                console.log(num);
                $('#b').html(num);
            })



        });
    </script>

</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col-2">
            <a href="javascript:history.go(-1);">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div class="col-10">
            <div class="input-group-sm search">
                <input class="form-control searchBtn" placeholder="搜索旅行攻略">
            </div>
        </div>
    </div>
</div>

<div class="container strategies">
    <h5 class="title"></h5>
    <small><span>0</span>人阅读过此攻略</small>
    <div class="focus">
        <i id="collectBtn" class="fa fa-heart-o"><span id="b"></span> 收藏</i>
        <i id="likeBtn" class="fa fa-thumbs-o-up"><span id="a"></span> 点赞</i>
        <button class="btn">想去</button>
        <button class="btn">去过</button>
    </div>
</div>
<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab">
    <li class="nav-item ">
        <a class="nav-link active" id="pills-catalog-tab" data-toggle="pill" href="#pills-catalog">
            <span>攻略目录</span>
        </a>
    </li>
    <li class="nav-item">
        <a class="nav-link " id="pills-comment-tab" data-toggle="pill" href="#pills-comment">
            <span>骡友点评</span>
        </a>
    </li>
</ul>
<div class="tab-content " id="pills-tabContent">
    <div class="tab-pane fade show active" id="pills-catalog">
        <div class="container hot">
            <h6>大家都在看</h6>
            <div render-loop="list">
                <a data-href="travelContent.html?id=" render-key="list.id" render-fun="getHref">
                    <button class="btn" render-html="list.title"></button>
                </a>
            </div>
        </div>
        <div class="catalogs">
            <div render-loop="list">
                <div class="container detail">
                    <h6 render-key="list.name" render-fun="getName"></h6>
                    <div render-loop="list.details">
                        <a data-href="strategyDetails.html?id=" render-key="list.details.id" render-fun="getHref">
                            <button class="btn" render-html="list.details.title"></button>
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="tab-pane fade " id="pills-comment">
        <div class="container tag">
            <h6>骡友标签</h6>
            <div>
                <span>价格便宜</span>
                <span>很热闹</span>
                <span>交通方便</span>
                <span>吃的很多</span>
                <span>风景优美</span>
                <span>美食很多</span>
                <span>很特别</span>
                <span>爱上这座城</span>
                <span>住宿方便</span>
                <span>刚刚</span>
            </div>
        </div>
        <hr>

        <div id="comment">
            <div render-loop="list">
                <div class="container row comment">
                    <div class="col-2 comment-head">
                        <a data-href="userProfiles.html?id=" render-key="list.user.id" render-fun="getId" >
                            <img class="rounded-circle"
                                 render-src="list.user.headImgUrl">
                        </a>
                    </div>
                    <div class="col comment-right">
                        <p class="authorName"><span render-html="list.user.nickName"></span></p>
                        <span class="comment-star" render-key="list.starNum" render-fun="getHref">

                        </span>
                        <span class="comment-date" render-html="list.createTime"></span>
                        <div class="comment-content">
                            <a data-href="strategyComment.html?id=" render-key="list.id" render-fun="getId">
                                <p render-html="list.content"></p>
                            </a>
                        </div>

                        <ul class="comment-img" render-key="list.imgUrls" render-fun="getImgs">
                            <li>

                            </li>
                        </ul>

                        <div class="d-flex icon">
                            <a href="strategyComment.html" >
                                <i class="fa fa-commenting-o " style="margin-right: 10px"> 评论 </i>
                            </a>
                        </div>
                    </div>
                </div>

                </div>
            </div>
        </div>

    </div>
</div>

<div class="operation">
    <button class="btn">加入旅行单</button>
    <button class="btn" id="commentBtn">点评</button>
</div>


</body>
</html>